package org.demo.work;

import java.util.concurrent.TimeUnit;

/**
 * 
 * @author  
 * @date    2010-10-27
 * @file    org.demo.work.PollEventWork.java
 */
public class PollEventWork implements Work{
	
	private String name;
	
	/**
	 * 构造函数
	 * @param name
	 */
	public PollEventWork(String name){
		this.name = name;
	}
	
	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void run() {
		for (int i=0; i<10; i++){
			try {
				System.out.println("work [" + name + "] running " + i);
				Thread.sleep(TimeUnit.SECONDS.toMillis(2));
				if (i == 3){
					throw new Exception("user stop work.");
				}
			} catch (Exception e) {
				throw new RuntimeException(e.getMessage());
			}
		}
	}	
}
